/**
 * 初始化窗口，根据传入参数判断加载哪个tab页
 * @param self
 * @param tiyData
 * @param tabShow
 */
export const recordInit = (self, tiyData, tabShow) => {
  tiyData.tData.importRecordList.splice(0,tiyData.tData.importRecordList.length);
  tiyData.tData.getInfoRecordList.splice(0,tiyData.tData.getInfoRecordList.length);
  tiyData.tGetInfoRecordPage.total = 1;
  tiyData.tGetInfoRecordPage.startIndex = 0;
  tiyData.tGetInfoRecordPage.stepNumber = 40;
  tiyData.tGetInfoRecordPage.currentPage = 1;
  tiyData.tImportRecordPage.total = 1;
  tiyData.tImportRecordPage.startIndex = 0;
  tiyData.tImportRecordPage.stepNumber = 40;
  tiyData.tImportRecordPage.currentPage = 1;
  if(tabShow == "importRecords"){
    searchImportRecords(self, tiyData);
    tiyData.tStatus.selectedTabs = "importRecords";
  } else if(tabShow == "getInfoRecords"){
    searchGetInfoRecords(self, tiyData);
    tiyData.tStatus.selectedTabs = "getInfoRecords";
  }
};

/**
 * 从服务器查询解析记录
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const searchGetInfoRecords = (self, tiyData) => {
  self.$Spin.show();
  self.$apiPlugin.getCustomerInfoRecordList({
    "pageSize": tiyData.tGetInfoRecordPage.stepNumber,
    "pageNum": tiyData.tGetInfoRecordPage.currentPage
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      let recordPage = response.result;
      tiyData.tGetInfoRecordPage.total = recordPage.total;
      tiyData.tData.getInfoRecordList.length = 0;
      recordPage.list.forEach(
        function (item) {
          tiyData.tData.getInfoRecordList.push(item);
        }
      );
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};

/**
 * 从服务器查询上传账户记录
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const searchImportRecords = (self, tiyData) => {
  self.$Spin.show();
  self.$apiPlugin.getImportRecordList({
    "pageSize": tiyData.tImportRecordPage.stepNumber,
    "pageNum": tiyData.tImportRecordPage.currentPage
  }).then(function (response) {
    self.$Spin.hide();
    tiyData.tData.importRecordList.splice(0, tiyData.tData.importRecordList.length);
    if (response.success) {
      let recordPage = response.result;
      tiyData.tImportRecordPage.total = recordPage.total;
      recordPage.list.forEach(
        function (item) {
          tiyData.tData.importRecordList.push(item);
        }
      );
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};

/**
 * 从在线参数中查询所有的目标客户来源平台
 * @param self
 * @param tiyData
 */
export const getCustomerPlatforms = (self, tiyData) => {
  self.$apiOther.querySysConfigValueByEnName({"sysConfigArgEnName":"customerPlatform"}).then(function(response){
    if (response.success) {
      self.$ySpliceAll(self.customerPlatforms);
      let platformArray = self.$toJson(response.result);
      for(let i = 0; i < platformArray.length; i++) {
        self.customerPlatforms.push(platformArray[i]);
      }
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};
